import os
import sys
import pymysql

# 将项目根目录添加到Python路径
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

def init_database():
    """初始化数据库"""
    try:
        # 连接MySQL
        conn = pymysql.connect(
            host='localhost',
            user='root',
            password='123456'
        )
        
        # 创建cursor
        with conn.cursor() as cursor:
            # 创建数据库
            cursor.execute("CREATE DATABASE IF NOT EXISTS landscape DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci")
            print("数据库创建成功！")
            
        conn.close()
        
    except Exception as e:
        print(f"初始化失败：{str(e)}")
        sys.exit(1)

if __name__ == '__main__':
    init_database() 